package _022_2_16

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func invertTree(root *TreeNode) *TreeNode {
	result := make([]*TreeNode, 0)

	result = append(result, root)

	for len(result) > 0 {
		size := len(result)

		for i := 0; i < size; i++ {
			if result[i] == nil {
				continue
			}
			result = append(result, result[i].Left)
			result = append(result, result[i].Right)
			temp := result[i].Left
			result[i].Left = result[i].Right
			result[i].Right = temp
		}
		result = result[1:]
	}

	return root
}
